package cn.ekuma.odbo.mobile.ui.adapter

import android.content.Context
import android.view.View
import android.widget.TextView

open class EntityAdapter<T,VH:View>(context: Context, entityList:List<T> = mutableListOf(), layoutId:Int, private val textViewId:Int=0, nullAble: Boolean =false, allAble: Boolean =false): AbstractEntityAdapter<T,VH>(context, entityList, layoutId,nullAble,allAble) {

    override fun displayItemToTextView(view: VH, item: T?, position: Int) {
        item?.let{
            val textView=if(textViewId>0) view.findViewById<TextView>(textViewId) else view as TextView
            if (item is CharSequence) {
                textView.text = item
            } else {
                textView.text = item.toString()
            }
        }
    }

    override fun displaySystemToView(view: VH, position: Int) {
        val textView=if(textViewId>0) view.findViewById<TextView>(textViewId) else view as TextView
        if(position<systemCount)
            textView.text = when {
                position == 0 && nullAble -> "NULL"
                else -> "ALL"
            }
    }

}